from pyGhp.allocate import allocator
from pyRvmp.swap import swaper
from time import clock

###################################
#        test variables           #
###################################

placed = False
placed = True
swaplimit = 5
k = 6

###################################

originPlace = {}
print 'orignial:',
svmp = swaper()
c1 = clock()
svmp.load('topo.in', 'host.in', 'vm.in')
print 'load and route:', clock() - c1
#print svmp.hosts.topo.matrix
c1 = clock()
svmp.set(swaplimit, 1)
print 'partition:', clock() - c1
if not placed: svmp.rand_place('place.in')
svmp.place('place.in')
#print svmp.hosts.topo.output()
for key, value in svmp.hosts.v2h.items():
    originPlace[key] = value
svmp.outputvm()
svmp.test()
#svmp.vms.output()
###################################

#print 'avmp:',
#avmp = allocator()
#avmp.load('host.in', 'topo.in', 'vm.in')
#avmp.cluster_and_cut(avmp.vms.vms, avmp.hosts.nodes, k)
#avmp.outputvm()
##print 'diff:',
#sum = 0
#for key, value in avmp.hosts.v2h.items():
#    if value != originPlace[key]:
#        sum = sum + 1
#print sum,
#asum = avmp.test()
asum = 120000

###################################

flag = True
print 'svmp:'
#svmp.limit = 1000
#svmp.adjustvm()
for sw in range(1000):
    print str(sw),
    svmp.limit = sw
    c1 = clock()
    svmp.adjustvm()
    #print 'time:', clock() - c1,
    #svmp.outputvm()
    #print 'diff:',
    sum = 0
    for key, value in svmp.hosts.v2h.items():
        if value != originPlace[key]:
            sum = sum + 1
    print sum,
    #svmp.outputvm()
    ssum = svmp.test()
    if ssum <= asum and flag:
        svmp.outputvm()
        flag = False
#svmp.test()